package com.ruoyi.sms.config;

import com.ruoyi.sms.config.property.SmsChannelProperties;
import com.ruoyi.sms.core.client.impl.aliyun.AliyunSmsClient;
import com.ruoyi.sms.core.client.impl.dingtalk.DingTalkSmsClient;
import com.ruoyi.sms.core.client.impl.tencent.TencentSmsClient;
import com.ruoyi.sms.core.enums.SmsChannelEnum;
import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;

import java.util.Map;

/**
 * 短信配置类
 *
 * @author ldl
 */
@Data
@ConfigurationProperties(prefix = "ruoyi.sms")
public class SmsAutoConfiguration {

    private Map<SmsChannelEnum, SmsChannelProperties> smsChannelPropMap;

    @Bean
    @ConditionalOnProperty(prefix = "ruoyi.sms.ALIYUN", name = "enabled", havingValue = "true")
    public AliyunSmsClient aliyunSmsClient() {
        return new AliyunSmsClient(smsChannelPropMap.get(SmsChannelEnum.ALIYUN));
    }

    @Bean
    @ConditionalOnProperty(prefix = "ruoyi.sms.DING_TALK", name = "enabled", havingValue = "true")
    public DingTalkSmsClient dingTalkSmsClient() {
        return new DingTalkSmsClient(smsChannelPropMap.get(SmsChannelEnum.DING_TALK));
    }

    @Bean
    @ConditionalOnProperty(prefix = "ruoyi.sms.TENCENT", name = "enabled", havingValue = "true")
    public TencentSmsClient tencentSmsClient() {
        return new TencentSmsClient(smsChannelPropMap.get(SmsChannelEnum.TENCENT));
    }

}
